package com.elong.businesstravel.modules.home.hotel.hotelshow;

import java.util.ArrayList;

import android.os.Bundle;
import android.os.Debug;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.android.support.jhf.debug.DebugLog;
import com.android.support.jhf.touchimageview.GalleryViewPager;
import com.elong.businesstravel.R;
import com.elong.businesstravel.base.baseactivity.BaseActivity;
import com.elong.businesstravel.base.view.TitleNavBarView;
import com.elong.businesstravel.entitys.HotelImage;
import com.elong.businesstravel.modules.home.hotel.adapter.HotelPictureAdapter;

/**
 * 酒店图片页
 * 
 * @author lenovo
 * 
 */
public class HotelPictureActivity extends BaseActivity {

	private GalleryViewPager mViewPager;
	private HotelPictureAdapter mHotelPictureAdapter;
	private TitleNavBarView mTitleNavBarView;

	private ArrayList<HotelImage> mHotelImages;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_hotel_picture);

		init();
	}

	@Override
	protected void init() {
		if (null == mSavedInstanceState) {
			mHotelImages = (ArrayList<HotelImage>) getIntent()
					.getSerializableExtra("images");
		} else {
			DebugLog.logI("1111111111111");
			mHotelImages = (ArrayList<HotelImage>) mSavedInstanceState
					.getSerializable("images");
		}

		mViewPager = (GalleryViewPager) findViewById(R.id.viewPager);
		mHotelPictureAdapter = new HotelPictureAdapter(mContext, mHotelImages);
		mViewPager.setAdapter(mHotelPictureAdapter);

		setTitleNavBar();

		setListener();
	}

	@Override
	protected void setListener() {
		mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {
				mTitleNavBarView.setMessage(mHotelImages.get(arg0).name + " "
						+ (arg0 + 1) + "/" + mHotelImages.size());
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {

			}
		});
	}

	@Override
	protected void setTitleNavBar() {
		mTitleNavBarView = (TitleNavBarView) findViewById(R.id.titleNavBarView);
		mTitleNavBarView.setMessage(mHotelImages.get(0).name + " " + "1/"
				+ mHotelImages.size());
		mTitleNavBarView.setLeftDrawableImage(R.drawable.btn_title_back);
		mTitleNavBarView.setLeftButtonImageString(0, "返回", R.color.text_blue);
		mTitleNavBarView.setLeftButtonOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// 返回
				finish();
			}
		});
		mTitleNavBarView.setRightButtonVisibility(View.INVISIBLE);
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		outState.putSerializable("images", mHotelImages);
		super.onSaveInstanceState(outState);
	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
		if (null != savedInstanceState) {
			mHotelImages = (ArrayList<HotelImage>) savedInstanceState
					.getSerializable("images");
		}
	}
}
